<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>상점관리</title>
<link href="/Jangdolbaeng2/css/customer/common1.css" rel="stylesheet">
<link href="/Jangdolbaeng2/css/bootstrap.min.css" rel="stylesheet">
<link href="/Jangdolbaeng2/css/customer/common.css" rel="stylesheet">
<script src="/Jangdolbaeng2/js/jquery-1.11.1.js"></script>
<script src="/Jangdolbaeng2/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	init();
})

function check()
{
	var product_name = $('#product_name').val();
	var product_price = $('#product_price').val();
	var product_image1 = $('#product_image1').val();
	var product_info1 = $('#product_info1').val();
	
	if(product_name == 0 || product_name == '')
	{
		alert('이름을 입력하시오');
		return false;
	}
	
	if(isNaN(product_price))
	{
		alert('숫자를 입력하시오');	
		return false;
	}
	
	if(product_price == 0 || product_price == '')
	{
		alert('가격을 입력하시오');
		return false;
	}
	
	if(product_image1 == '')
	{
		alert('이미지를 최소 1개 추가하시오');
		return false;
	}
	
	if(product_info1 == 0 || product_info1 == '')
	{
		alert('상품정보를 입력하시오');
		return false;
	}
	
	return true;
}

function shopProduct(shopseq)
{
	location.href="/Jangdolbaeng2/admin/shopProduct.action?productVO.shop_seq=" + shopseq;
}

function init()
{
	$.ajax({
		url: 'shopNameList.action',
		type: 'POST',
		dateType: 'json',
		success: shopNameOutput
	});
}

function shopNameOutput(json)
{
	$('#listDiv1').html('');
	$('#listDiv2').html('');
	
	var str = '<center>';
	str += '<table class="table table table-striped table-hover table-bordered" style="text-align: center; width: 350px;">';	
	str += '<td  class="success" style="font-weight: bold" colspan="2">' + '상점이름' + '</td>';
	$.each(json.shopNameList , function(key, item){
	str += '<tr>'; 
	str += '<td width="50">' + '<a style="color: blue;" href="' + 'javascript:shopList(' + item.shop_seq + ')">' + item.shop_seq + '</a>' + '</td>';
	str += '<td>' + item.name + '</td>';
	str += '</tr>';
	});
	str += '</table>'; 
	str += '</center>';
	$('#listDiv1').html(str);
}

function shopList(shop_seq)
{
	$.ajax({
		url: 'shopList.action',
		type: 'POST',
		dateType: 'json',
		data: {
			shop_seq: shop_seq,
		},
		success: shopOutput
	});
}

function shopOutput(json){
	
	$('#listDiv1').html('');
	$('#listDiv2').html('');
	
	var str = '&nbsp';
	var str2 = '&nbsp';
	
	$.each(json.shopList, function(key, item){
	str += '<center>';
	str += '<table class="table table table-striped table-hover table-bordered" style="text-align: center; width: 800px;">';
	str += '<td style="font-weight: bold">' + '상점이름' + '</td>';
   	str += '<td style="font-weight: bold">' + '카테고리' + '</td>';
   	str += '<td style="font-weight: bold">' + '우편번호' + '</td>';
   	str += '<td style="font-weight: bold">' + '상점주소' + '</td>';
   	str += '<td style="font-weight: bold">' + '상점전화번호' + '</td>';
   	str += '<td style="font-weight: bold">' + '판매자아이디' + '</td>';
   	str += '<td style="font-weight: bold">' + '상인탈퇴' + '</td>';
   	
   	str += '<tr>';
   	str += '<td>' + '<a style="color: blue;" href="' + 'javascript:shopProduct(' + item.shop_seq + ')">' + item.name + '</a>' +  '</td>';
	if(item.category == 'f'){
   		str += '<td>' + '과일류' + '</td>';
	}
	else if(item.category == 'v'){
		str += '<td>' + '채소류' + '</td>';
	}
	else if(item.category == 'i'){
		str += '<td>' + '생선류' + '</td>';
	}
	else if(item.category == 'm'){
		str += '<td>' + '육류' + '</td>';
	}
	else if(item.category == 'g'){
		str += '<td>' + '식료품류' + '</td>';
	}
	else if(item.category == 'h'){
		str += '<td>' + '건강용품' + '</td>';
	}
	else if(item.category == 'a'){
		str += '<td>' + '패션' + '</td>';
	}
	else if(item.category == 'l'){
		str += '<td>' + '생활용품' + '</td>';
	}
	else if(item.category == 'e'){
		str += '<td>' + '기타' + '</td>';
	}
	str += '<td>' + item.zipcode + '</td>';
	str += '<td>' + item.address1 + ' ' + item.address2 + '</td>';
	str += '<td>' + item.phone + '</td>';
	str += '<td id="seller_id">' + item.seller_id + '</td>';
	});
	
	$.each(json.shopList, function(key, item){
		str += '<td>' + '<button type="button" class="btn btn-success" onclick="javascript:sellerDelete()">' + '상인탈퇴' + '</button>'  +  '</td>';
	});
	
	str += '</tr>';
    str += '</table>';
    str += '</center>';
  
    str2 += '<h3 align="center" style="margin-top: 50px; margin-bottom: 20px;"><span class="glyphicon glyphicon-tag"></span> <span style="font-family: anew">상품등록</span></h3>';
    str2 += '<center>';
    str2 += '<form name="productVO" action="insertProduct" onsubmit="return check()" method="post" enctype="multipart/form-data">';
    str2 += '<table class="table table table-striped table-hover table-bordered" style="text-align: center; width: 500px;">';
    $.each(json.shopList, function(key, item){
    str2 += '<s:hidden name="productVO.product_category" value="' + item.category + '" />';
    str2 += '<s:hidden name="productVO.shop_seq" value="' + item.shop_seq + '" />';
    str2 += '<tr>';
    str2 += '<th>' + '상품이름' + '</th>';
    str2 += '<td>' + '<s:textfield size="53" id="product_name" name="productVO.product_name" theme="simple"/>' + '</td>';
    str2 += '</tr>';
    str2 += '<tr>';
    str2 += '<th>' + '상품가격' + '</th>';
    str2 += '<td>' + '<s:textfield size="53" id="product_price" name="productVO.product_price" theme="simple"/>' + '</td>';
    str2 += '</tr>';
    str2 += '<tr>';
    str2 += '<th>' + '상품사진1' + '</th>';
    str2 += '<td>' + '<input type="file" id="product_image1" name="uploads" />' + '</td>';
    str2 += '</tr>';
    str2 += '<tr>';
    str2 += '<th>' + '상품사진2' + '</th>';
    str2 += '<td>' + '<input type="file" name="uploads" />' + '</td>';
    str2 += '</tr>';
    str2 += '<tr>';
    str2 += '<th>' + '정보1' + '</th>';
    str2 += '<td>' + '<s:textarea id="product_info1" name="productVO.product_info1" cssStyle="width:400px;height:250px;resize:none" theme="simple"/>' + '</td>';
    str2 += '</tr>';
    str2 += '<tr>';
    str2 += '<th>' + '정보2' + '</th>';
    str2 += '<td>' + '<s:textarea name="productVO.product_info2" cssStyle="width:400px;height:250px;resize:none" theme="simple"/>' + '</td>';
    str2 += '</tr>';
    str2 += '<tr>';
    str2 += '<td colspan="2">';
    str2 += '<input type="submit" value="저장">';
    str2 += '</td>';
    str2 += '</tr>';
    str2 += '</table>';
    str2 += '</form>';
    str2 += '</center>';
    });
    
    $('#listDiv1').html(str);
    $('#listDiv2').html(str2);
}

function sellerOutput(json){
	$('#listDiv1').html('');

	var str = '<center>';
	str += '<table border="1">';
    $.each(json.sellerList, function(key, item){
    	str += '<th>' + '판매자이름' + '</th>';
    	str += '<th>' + '우편번호' + '</th>';
    	str += '<th>' + '판매자주소1' + '</th>';
    	str += '<th>' + '판매자주소2' + '</th>';
    	str += '<th>' + '판매자전화번호' + '</th>';
    	str += '<th>' + '판매자이메일' + '</th>';

    	str += '<tr>';
		str += '<td>' + '<a href="' + 'shopProduct.action' +  '">' + item.name + '</a>' +  '</td>';
		str += '<td>' + item.zipcode + '</td>';
		str += '<td>' + item.address1 + '</td>';
		str += '<td>' + item.address2 + '</td>';
		str += '<td>' + item.phone + '</td>';
		if(item.email == null)
		{
			str += '<td>' + '없음' + '</td>';
		}else{
		str += '<td>' + item.email + '</td>';
		}
		str += '</tr>';
    	
    });
    str += '</table>';
    str += '</center>';

    $('#listDiv1').html(str);
}//sellerOutput()



</script>

</head>
<body>
<div id="header">
	<%@ include file="adminHeader.jsp" %>
</div>
<div class="container">
	<h3 align="center" style="margin-top: 50px; margin-bottom: 20px;"><span class="glyphicon glyphicon-home"></span> <span style="font-family: anew">상점관리</span></h3>
	
 	<div id="listDiv1"></div>
 	<div id="listDiv2"></div>
</div>
</body>
</html>